package com.tgr.shortLink.admin.controller;

import com.tgr.shortLink.admin.common.convention.result.Result;
import com.tgr.shortLink.admin.common.convention.result.Results;
import com.tgr.shortLink.admin.dto.req.GroupSortReqDTO;
import com.tgr.shortLink.admin.dto.req.GroupUpdateReqDTO;
import com.tgr.shortLink.admin.dto.resp.GroupListRespDTO;
import com.tgr.shortLink.admin.dto.req.GroupSaveReqDTO;
import com.tgr.shortLink.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：
 * 作者：小陶不慌张
 * 文件：GroupController
 * 日期：2024/1/14 0:11
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/short-link/admin/v1/group")
public class GroupController {
    private final GroupService groupService;

    @PostMapping("")
    public Result<Void>saveGroup(@RequestBody GroupSaveReqDTO requestParam){
        groupService.saveGroup(requestParam.getName());
        return Results.success();
    }

    @GetMapping("")
    public Result<List<GroupListRespDTO>>listGroup(){
        return Results.success(groupService.listGroup());
    }

    @PutMapping("")
    public Result<Void>updateGroup(@RequestBody GroupUpdateReqDTO requestParam){
        groupService.updateGroup(requestParam);
        return Results.success();
    }

    @DeleteMapping("")
    public Result<Void>deleteGroup(@RequestParam String gid){
        return Results.success();
    }

    @PostMapping("/sort")
    public Result<Void>sortGroup(@RequestBody List<GroupSortReqDTO> requestParam){
        groupService.sortGroup(requestParam);
        return Results.success();
    }
}
